//
//  ProgressDetailViewController.m
//  EducationOID
//
//  Created by slz on 2017/8/25.
//  Copyright © 2017年 bnsr. All rights reserved.
//

#import "ProgressDetailViewController.h"
#import "ProgressTextField.h"
#import "BaseHttpTool.h"

@interface ProgressDetailViewController ()<UITextFieldDelegate>
@property (nonatomic,strong) ProgressTextField *field1;
@property (nonatomic,strong) ProgressTextField *field2;
@property (nonatomic,strong) ProgressTextField *field3;
@property (nonatomic,strong) ProgressTextField *field4;

@end

@implementation ProgressDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.showNavigationBar = YES;
    [self setControllerTitle:@"OID申请进度"];
    self.view.backgroundColor = kChange_InfoColor_bakc_Default;
    UIBarButtonItem * item = [UIBarButtonItem itemWithImage:@"top_back_1" selectImage:nil addTarget:self andAction:@selector(backAction)];
    self.navigationItem.leftBarButtonItem = item;

    [self initTextView];
    // Do any additional setup after loading the view.
}

-(void)initTextView{
    _field1 = [[ProgressTextField alloc]initWithLeftLabelTitle:@"OID值:"];
    _field1.delegate = self;
    [self.view addSubview:_field1];
    [_field1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(11);
        make.trailing.mas_equalTo(-11);
        make.top.mas_equalTo(self.view.mas_top).offset(40);
        make.height.mas_equalTo(40);
    }];
    
    _field2 = [[ProgressTextField alloc]initWithLeftLabelTitle:@"OID描述:"];
    _field2.delegate = self;
    [self.view addSubview:_field2];
    [_field2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(11);
        make.trailing.mas_equalTo(-11);
        make.top.mas_equalTo(_field1.mas_bottom).offset(20);
        make.height.mas_equalTo(40);
    }];

    _field3 = [[ProgressTextField alloc]initWithLeftLabelTitle:@"时间:"];
    _field3.delegate = self;
    [self.view addSubview:_field3];
    [_field3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(11);
        make.trailing.mas_equalTo(-11);
        make.top.mas_equalTo(_field2.mas_bottom).offset(20);
        make.height.mas_equalTo(40);
    }];
    
    _field4 = [[ProgressTextField alloc]initWithLeftLabelTitle:@"OID申请状态:"];
    _field4.delegate = self;
    [self.view addSubview:_field4];
    [_field4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(11);
        make.trailing.mas_equalTo(-11);
        make.top.mas_equalTo(_field3.mas_bottom).offset(20);
        make.height.mas_equalTo(40);
    }];
    
    @weakify(self);
    [BaseHttpTool get:kAPI_SHOW_OID_DETAIL params:@{@"id":self.oid} success:^(id responseObj) {
        MFWJson * json = [MFWJson jsonWithObject:responseObj];
        @strongify(self);
        [self updateInfoWithJson:json];
    } failure:^(NSError *error) {
        [self.view showTip:error.localizedDescription];
    }];
}

- (NSString *)stateWithNumber:(NSInteger)number{
    NSString * string = @"unknow";
    switch (number) {
        case 1:
            string = @"完成提交申请";
            break;
        case 2:
            string = @"完成审核";
            break;
        case 3:
            string = @"公示中";
            break;
        case 4:
            string = @"完成发布";
            break;
        case 5:
            string = @"审核未通过";
            break;
        default:
            string = @"unknow";
            break;
    }
    return string;
}

-(void)updateInfoWithJson:(MFWJson *)json{
    MFWJson * subJson = [json jsonForKey:@"oid_info"];
    _field1.text = [subJson stringValueForKey:@"number"];
    _field2.text = [subJson stringValueForKey:@"apply_description"];
    _field3.text = [subJson stringValueForKey:@"time"];
    NSInteger number = [subJson intValueForKey:@"status"];
    
    _field4.text = [self stateWithNumber:number];;
}

-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
    return NO;
}

- (void)backAction{
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self.view endEditing:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
